﻿using System.Windows.Media;
using Socium.Domain.Documents;
using Socium.Presentation;

namespace Socium.Documents {
	public class RelationGroupViewModel : ViewModelBase {
		readonly RelationGroup _relation_group;

		public RelationGroupViewModel(RelationGroup relation_group) {
			_relation_group = relation_group;
			var color = GetColor(relation_group.Color);
			Brush = new SolidColorBrush(color);
		}

		static Color GetColor(int value) {
			return Color.FromRgb(GetValue(value, 0), GetValue(value, 8), GetValue(value, 16));
		}

		static byte GetValue(int value, int offset) {
			return (byte) ((value << offset) & 0xFF);
		}

		public Brush Brush { get; private set; }

		public RelationGroup RelationGroup {
			get { return _relation_group; }
		}

		public string Name {
			get { return _relation_group.Name; }
			set {
				_relation_group.Name = value;
				OnPropertyChanged("Name");
			}
		}
	}
}
